import { http } from "@/utils/http";
import type { TableItem } from "../type";
type ResultTable = {
  total?: number;
  data?: Array<any>;
};

//查询排放因子
export const emissionFactorquery = (data?: object) => {
  return http.request<ResultTable>("post", `/energy/api/v1/emissionFactor/query`, {
    data
  });
};
// 排放因子来源列表
export const emissionFactorSourceList = (params: object | undefined) =>
  http.request(
    "get",
    `/energy/api/v1/emissionFactor/emissionFactorSourceList`,
    { params },
    {
      headers: { noLoading: false }
    }
  );
// 排放因子分子单位列表
export const numberatorUnitList = (params: object | undefined) =>
  http.request(
    "get",
    `/energy/api/v1/emissionFactor/moleculeUnitList`,
    { params },
    {
      headers: { noLoading: false }
    }
  );
// 排放因子分母单位列表
export const denominatorUnitList = (params: object | undefined) =>
  http.request(
    "get",
    `/energy/api/v1/emissionFactor/denominatorUnitList`,
    { params },
    {
      headers: { noLoading: false }
    }
  );
//新增排放因子
export const emissionFactorsave = (data?: object) => {
  return http.request<ResultTable>("post", `/energy/api/v1/emissionFactor/save`, {
    data
  });
};
//排放因子详情
export const emissionFactordetail = (data?: object) => {
  return http.request<ResultTable>("post", `/energy/api/v1/emissionFactor/detail`, {
    data
  });
};
//删除排放因子
export const emissionFactordelete = (data?: object) => {
  return http.request<ResultTable>("post", `/energy/api/v1/emissionFactor/delete`, {
    data
  });
};
//修改排放因子
export const emissionFactoredit = (data?: object) => {
  return http.request<ResultTable>("post", `/energy/api/v1/emissionFactor/edit`, {
    data
  });
};
//查询碳排放数据源报警记录
export const accountingReportledger = (data?: object) => {
  return http.request<ResultTable>("post", `/energy/accountingReport/ledger`, {
    data
  });
};
//查看一个设施活动碳排放数据源详情
export const accountingReportemissionDataDetail = (data?: object) => {
  return http.request<ResultTable>("post", `/energy/accountingReport/emissionDataDetail`, {
    data
  });
};
//编辑一个设施活动的碳排放数据源
export const accountingReporteditEmissionData = (data?: object) => {
  return http.request<ResultTable>("post", `/energy/accountingReport/editEmissionData`, {
    data
  });
};
//查看某一种设施活动核算历史记录
export const accountingReportrecord = (data?: object) => {
  return http.request<ResultTable>("post", `/energy/accountingReport/record`, {
    data
  });
};
//排放因子导入
export const emissionFactoruploadFile = (data?: object | undefined, cb?: (err: any) => any) =>
  http.request<Array<TableItem>>(
    "post",
    `/energy/api/v1/emissionFactor/uploadFile`,
    { data },
    { headers: { noLoading: true, "Content-Type": "multipart/form-data" } },
    cb
  );

//导入设施活动
export const facilityuploadFile = (data?: object | undefined, cb?: (err: any) => any) =>
  http.request<Array<TableItem>>(
    "post",
    `/energy/api/v1/facility/uploadFile`,
    { data },
    { headers: { noLoading: true, "Content-Type": "multipart/form-data" } },
    cb
  );

// 获取数据来源
export const getDataSource = () => {
  return http.request<ResultTable>(
    "get",
    `/energy/digitaltwinsConfig/dataSource`,
    {},
    {
      headers: { noLoading: false }
    }
  );
};

// 通过主键删除可视化配置
export const deleteDigitaltwinsConfig = (id: number) => {
  return http.request<any>("post", `/energy/digitaltwinsConfig/delete/${id}`);
};

// 查询可视化配置
export const queryDigitaltwinsConfig = (data?: object) => {
  return http.request<any>("post", `/energy/digitaltwinsConfig/query`, {
    data
  });
};
// 更新可视化配置
export const updateDigitaltwinsConfig = (data?: object) => {
  return http.request<any>("post", `/energy/digitaltwinsConfig/update`, {
    data
  });
};

// 排放因子-历史记录
export const getemissionFactorHistory = (data?: object) => {
  return http.request<any>("post", `/energy/api/v1/emissionFactor/history`, {
    data
  });
};

// 核算边界-查询当前版本是否有草稿
export const queryDraft = (data?: object) => {
  return http.request<any>("post", `/energy/accountingTemplate/queryDraft`, {
    data
  });
};
// 核算边界-删除当前草稿并重新生成一个草稿
export const deleteDraft = (data?: object) => {
  return http.request<any>("post", `/energy/accountingTemplate/deleteDraft`, {
    data
  });
};
// 核算边界-根据当前最新版本生成一个草稿
export const createDraft = (data?: object) => {
  return http.request<any>("post", `/energy/accountingTemplate/draft`, {
    data
  });
};
// 核算边界-获取草稿详情
export const getDraftDetail = (data?: object) => {
  return http.request<any>("post", `/energy/accountingTemplate/draftDetail`, {
    data
  });
};

// 核算边界-保存草稿为新版本
export const saveNewVersion = (data?: object) => {
  return http.request<any>("post", `/energy/accountingTemplate/saveNewVersion`, {
    data
  });
};

// 核算边界-查询历史版本
export const queryHistoryVersion = (data?: object) => {
  return http.request<any>("post", `/energy/accountingTemplate/history`, {
    data
  });
};
